package com.gangan.controller.web;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gangan.controller.common.BaseController;
import com.gangan.model.User;
import com.gangan.service.IUserService;
import com.gangan.tools.MessageBean;
import com.sun.org.apache.bcel.internal.generic.IUSHR;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户模块控制层
 */
@Api(description = "*用户模块控制层")
@RestController
@RequestMapping("/user")
public class UserController extends BaseController {
    @Autowired
    IUserService userService;

    @RequestMapping(value = "/list",method = RequestMethod.GET)
    @ApiOperation(value="用户列表", notes="根据相关条件查询列表数据")
    public MessageBean list(Page page){
        return resultSuccess(userService.page(page));
    }

    @RequestMapping(value = "/del",method = RequestMethod.POST)
    @ApiOperation(value="移除用户", notes="根据自增主键移除数据")
    public MessageBean del(Integer id){
        return resultSuccess(userService.removeById(id));
    }

    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @ApiOperation(value="新增用户", notes="将提交的数据保存到数据库")
    public MessageBean add(User add){
        return resultSuccess(userService.save(add));
    }

    @RequestMapping(value = "/edit",method = RequestMethod.POST)
    @ApiOperation(value="编辑用户", notes="根据主键修改数据")
    public MessageBean edit(User edit){
        return resultSuccess(userService.updateById(edit));
    }

}
